package com.xy.biz.fd.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.fd.domain.bo.RepositoryBO;
import com.xy.biz.fd.domain.po.RepositoryPO;
import com.xy.biz.fd.domain.query.RepositoryQuery;
import com.xy.biz.fd.domain.req.repository.SaveRepositoryRequest;
import com.xy.biz.fd.domain.req.repository.ListRepositoryRequest;
import com.xy.biz.fd.domain.resp.GetRepositoryResponse;
import com.xy.tool.util.BeanUtilsEx;

/**
 *
 *
 * @author ssl
 * @date 2021-1-18
 */
public class RepositoryConverter {

	public static RepositoryPO toPO(RepositoryBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RepositoryPO(), true);
	}

	public static List<RepositoryPO> toPO(Collection<RepositoryBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RepositoryPO(), true);
	}

	public static RepositoryBO fromPO(RepositoryPO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RepositoryBO());
	}

	public static List<RepositoryBO> fromPO(Collection<RepositoryPO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RepositoryBO());
	}

	public static RepositoryBO toBO(SaveRepositoryRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new RepositoryBO(), true);
	}

	public static List<RepositoryBO> toBO(Collection<SaveRepositoryRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RepositoryBO(), true);
	}

	public static GetRepositoryResponse toResponse(RepositoryBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new GetRepositoryResponse());
	}

	public static List<GetRepositoryResponse> toResponse(Collection<RepositoryBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetRepositoryResponse());
	}

	public static RepositoryQuery toQuery(ListRepositoryRequest source) {
		if(null == source) {
			return null;
		}
		RepositoryQuery target = new RepositoryQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

	public static RepositoryQuery toQueryMax(ListRepositoryRequest source) {
		if(null == source) {
			return null;
		}
		RepositoryQuery target = RepositoryQuery.max().build();
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

	public static RepositoryQuery SaveToQuery(SaveRepositoryRequest request) {
		if (request == null) {
			return null;
		}
		return BeanUtilsEx.copyProperties(request, () -> new RepositoryQuery(), true);
	}

}
